package com.zjpavt.client.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * 定时任务具体执行类
 * @author gxy
 */
public class TimingJob implements Job {
    /**
     * 根据type的不同执行不同的操作
     *
     * @param context
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        final JobRunner jobRunner = JobRunner.getInstance();
        switch (context.getJobDetail().getJobDataMap().getString("TYPE")) {
        case JobManager.TIMING_JOB_TYPE_K_NOTWITHTIME_COMMAND: {
            jobRunner.switchToKCommandWithoutTime();
            break;
        }
        case JobManager.TIMING_JOB_TYPE_REFRESH_OFFLINE_COMMAND: {
            jobRunner.refreshOfflineCommand();
            break;
        }
        case JobManager.TIMING_JOB_TYPE_REFRESH_TODAY_TIMER_COMMAND: {
            jobRunner.refreshTodayTimerCommand();
            break;
        }
        case JobManager.TIMING_JOB_TYPE_SWITCH_TO_TIMER_COMMAND: {
            jobRunner.switchToTodayTimerCommand();
            break;
        }
        case JobManager.TIMING_JOB_TYPE_CLOSE_TODAY_TIMER_COMMAND: {
            if (jobRunner.getState() <= JobRunner.EXECUTOR_TODAYTIMER_COMMAND_STATE) {
                jobRunner.switchToOfflineCommand();
            }
            break;
        }
        default:
            break;
        }
    }
}
